package watcher.example;

import java.util.ArrayList;
import java.util.List;

/**
 * 被观察者实现类，里面有个管理观察者的数组，通过遍历数组触发事件
 * Created by yangliwei on 2018/4/12.
 */
public class EventObject implements Event{
    List<Listener> listeners = new ArrayList<>();

    public void notifyListeners(){
        for(int i =0;i<listeners.size();i++){
            listeners.get(i).handlerEvent();
        }
    }

    @Override
    public void addListener(Listener listener) {
        this.listeners.add(listener);
    }


    public static void main(String[] args) {
        EventObject event  = new EventObject();
        event.addListener(new Listener1());
        event.addListener(new Listener2());
        event.notifyListeners();
    }
}
